package com.itcast.service.impl;

import com.itcast.mapper.DeptMapper;
import com.itcast.pojo.Dept;
import com.itcast.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    /*
    * 查询所有部门
    * */
    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }
    /*
    * 根据id删除部门
    * */
    @Override
    public void deleteDeptById(Integer id) {
        deptMapper.deleteDeptById(id);
    }
    /*
    * 添加部门
    * */
    @Override
    public void addDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        dept.setCreateTime(LocalDateTime.now());
        deptMapper.addDept(dept);
    }
    /*
    * 根据id查询部门
    * */
    @Override
    public Dept findDeptById(Integer id) {
        return deptMapper.findDeptById(id);
    }
    /*
    * 根据id修改部门
    * */
    @Override
    public void updateDeptById(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDeptById(dept);
    }
}
